package org.ajie.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@NoArgsConstructor
@AllArgsConstructor
@Data
public class Result<T> implements Serializable {

    /**
     * 响应码
     */
    private int code;
    /**
     * 响应消息
     */
    private String message;
    /**
     * 响应数据
     */
    private T data;


    public Result(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result(String message, T data) {
        this.message = message;
        this.data = data;
    }

    public static Result success() {
        return new Result(200, "成功!");
    }
    public static <T> Result<T> success(T data) {
        return new Result(200, "成功", data);
    }
    public static Result error() {
        return new Result(500, "失败!");
    }
    public static Result error(String message) {
        return new Result(500, "失败!");
    }
    public static Result success(String message) {
        return new Result(200, message);
    }
    public static <T> Result<T> success(String message,T data) {
        return new Result(200, message, data);
    }
    public static Result success(int code, String message) {
        return new Result(code, message);
    }
    public static Result error(int code,String message) {
        return new Result(code, message);
    }
    public static <T> Result<T> error(int code,String message,T data) {
        return new Result(code, message,data);
    }

}
